﻿var CContextMenu = function (opts) {
    var self = this;
    this.firstTime = true;
    this.container = "";
    this.options = {};
    $.extend(true, self.options, opts);
    this.Init = function (container) {
        self.container = container;
        var options = self.options;
        var items = options.items;
        items["sep1"] = "---------";
        items["quit"] = { name: "Đóng", icon: "quit", callback: function () { return true; } };
        $.contextMenu({
            selector: container,
            items: items,
            events: {
                show: function (opt) {
                    if (self.firstTime != true) {
                        // this is the trigger element
                        var $this = this;
                        // import states from data store 
                        $.contextMenu.setInputValues(opt, $this.data());
                        // this basically fills the input commands from an object
                        // like {name: "foo", yesno: true, radio: "3", …}
                    }
                    self.firstTime = false;
                },
                hide: function (opt) {
                    // this is the trigger element
                    var $this = this;
                    // export states to data store
                    $.contextMenu.getInputValues(opt, $this.data());
                    // this basically dumps the input commands' values to an object
                    // like {name: "foo", yesno: true, radio: "3", …}
                }
            }
        });
    };
};